package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.UploadFile;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UploadFileMapper {

    @Select({"<script>"+
            "select * from file_attachment " +
            "<where>  " +
            "<if test='pid != null '>and project_id = #{pid} </if>" +
            "<if test='projectName != null and projectName.length &gt; 0'>and project_name = #{projectName} </if>" +
            "<if test='fileType != null  '>and file_type = #{fileType} </if>" +
            "</where></script>"})
    List<UploadFile> findByIdType(@Param("pid") Integer pid,
                         @Param("projectName") String projectName,
                         @Param("fileType") Integer fileType);

 /*   @Select({"select * from file_attachment " +
            "where project_id = #{pid} and project_name = #{projectName} " +
            "and file_type = #{fileType}  "})
    @Results({@Result(property = "projectId", column = "project_id"),
            @Result(property = "projectName", column = "project_name"),
            @Result(property = "createDate", column = "create_date")})
    List<UploadFile> findByIdType(@Param("pid") Integer pid,
                                  @Param("projectName") String projectName,
                                  @Param("fileType") Integer fileType);*/

    @Insert({"insert into file_attachment (project_id,project_name,file_type,content,create_date) " +
            "values (#{projectId},#{projectName},#{fileType},#{content},#{createDate})"})
    Integer add(UploadFile uploadFile);

    @Delete({"delete from file_attachment where id=#{id}"})
    Integer remove(int i);

    @Delete({"update file_attachment set project_no=#{projectNo},where project_id = #{projectId} and project_name = #{projectName} "})
    Integer update(UploadFile uploadFile);

    @Delete({"delete from file_attachment where project_id = #{projectId} and project_name = #{projectName} "})
    Integer delete(@Param("projectId") int i, @Param("projectName") String str);

    @Select({"select * from file_attachment where id = #{id}"})
    @Results({@Result(property = "projectId", column = "project_id"), @Result(property = "projectName", column = "project_name"), @Result(property = "createDate", column = "create_date")})
    UploadFile findById(@Param("id") int i);
}